<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="*|/"><xsl:apply-templates/></xsl:template>

<xsl:template match="text()|@*"><xsl:value-of select="."/></xsl:template>

<xsl:template match='nbsp' name='nbsp'>
<xsl:text disable-output-escaping='yes'>&amp;nbsp;</xsl:text>
</xsl:template>

<xsl:template match="Registration">
<!-- Insert appropriate Validation -->
<xsl:variable name="PWID" select='/Question[(@Type="12")]
											 /@RP3'/>

<script>
function validateForm() {
document.returnValue = true;
<xsl:for-each select="Question">
	<xsl:if test='@Type!="8"'>
		<xsl:if test='@Type="3"'>
			var ric = document.getElementById("R5").value;
			var che = document.getElementById("R5").checked;
			if( ric=="894" )
			if( che==false ) {
				var gg = document.getElementById("gg<xsl:value-of select="@ID"/>").value;
				var mm = document.getElementById("mm<xsl:value-of select="@ID"/>").value;
				var aa = document.getElementById("aaaa<xsl:value-of select="@ID"/>").value
				if (isDate(	gg, mm, aa)){
	//				alert("Bravo hai inserito una data di nascita valida!");
					document.returnValue = true;
				}else{
					alert("Inserisci una data dell'evento valida, dai!");
					document.returnValue = false;
				}
			}
		</xsl:if>

		<xsl:if test='@Type="4"'>
			email = document.getElementById("E<xsl:value-of select="@ID"/>").value;
			if( isEmail(email) ){
				alert("Inserisci un email address valido, dai!");
				document.returnValue = false;
			}
		</xsl:if>

		<xsl:if test='@Type="11"'>
			isUsername(document.getElementById("T<xsl:value-of select="@ID"/>").value);
		</xsl:if>

		<xsl:if test='@Type="12" and @ID=@RP3'>
			password1 = document.getElementById("T<xsl:value-of select="@ID"/>").value;
			password2 = document.getElementById("T<xsl:value-of select="@RP3"/>").value;
			isPassword(password1,password2);
		</xsl:if>

	</xsl:if>
</xsl:for-each>
}
</script>
<!-- End of Insert appropriate Validation -->

<table bgcolor="#f4efdf" class="nbox" border="0" cellspacing="8" cellpadding="0" width="100%">
<form name="formRegistration" method="post" action="{@action}?holidayId={/Registration/@holidayId}" onSubmit="validateForm();return document.returnValue">
<tr>
<input type="hidden" name="FORM_ID" value="{concat('FORM',@ID)}"></input>
<input type="hidden" name="HOLIDAY_ID" value="{@holidayId}"></input>
<td colspan="4">
</td>
</tr>

<xsl:variable name="nextForm">
<xsl:for-each select="Question">
<xsl:choose>
	<xsl:when test='@Type="16"'>
			<xsl:value-of select="@P1"/>
	</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:variable>

<xsl:for-each select="Question">
<xsl:choose>
	<xsl:when test='@Type="16"'>
		<xsl:variable name="next">
			<xsl:value-of select="@P1"/>
		</xsl:variable>
	</xsl:when>
	<xsl:when test='@Type="15"'>
		<tr><td colspan="4" align="center">
		<a href="{@P3}"><xsl:value-of select="@Description"/></a>
		<br/><span class="body_10px_red"><xsl:value-of select="@Comment"/></span>
		</td></tr>
	</xsl:when>
	<xsl:when test='@Type="14"'>
		<tr><td colspan="4" align="center">
		<input id="SB{@ID}" name="SB{@ID}" onClick="javascript:link('{@P3}');" type="button" value="{@Description}"></input>
		<br/><span class="body_10px_red"><xsl:value-of select="@Comment"/></span>
		</td></tr>
	</xsl:when>
	<xsl:when test='@Type="8"'>
		<tr><td colspan="4" align="center">
		<input type="hidden" name="nextForm" value="{$nextForm}"></input>
		<br/><input type="submit" name="{concat('SUBMIT',@ID)}" value="{@Description}"></input><br/>
		</td></tr>
	</xsl:when>
	<xsl:when test='@Type="9"'>
		<tr><td colspan="4" align="center"><h4><xsl:value-of select="@Description"/></h4></td></tr>
	</xsl:when>
	<xsl:when test='@Type="10" and @P1="0"'>
		<tr><td colspan="4" align="left"><xsl:value-of select="@Comment"/></td></tr>
		<tr><td colspan="4" align="left"></td></tr>
	</xsl:when>
	<xsl:when test='@Type="10" and @P1="1"'>
		<tr><td colspan="3"></td>
			<td colspan="1" align="left"><xsl:value-of select="@Comment"/></td></tr>
		<tr><td colspan="4" align="left"></td></tr>
	</xsl:when>
	<xsl:otherwise>
		<tr>
		<td>
		<xsl:value-of select="@Description"/>
		</td><td align="right">
		</td><td>

		</td>
		<td>

		<xsl:if test='@Type="7"'>
		<xsl:variable name="TMPID" select="@ID"></xsl:variable>
			<xsl:for-each select='Answer'>
			<table cellspacing="0" cellpadding="0">
				<xsl:if test='@Type="4"'>
					<tr><td><input type="text" name='SE{../@ID}' size="35" maxlength="64"></input></td></tr>
				</xsl:if>
				<xsl:if test='@Type="1"'>
					<tr><td>
					<select class="body" size="1" name="{concat('SD',@ID)}">
					<xsl:for-each select="SubAnswer">
					<option value="{@ID}"><xsl:value-of select="."/></option>
					</xsl:for-each>
					</select>
					</td></tr>
				</xsl:if>
			</table>
			</xsl:for-each>
		</xsl:if>

		<xsl:if test='@Type="1" and @ID="4"'>
		<select class="body" size="1" name="D{@ID}">
			<xsl:for-each select="Answer">
				<xsl:choose>
				  <xsl:when test='@ID=/Registration/Question/@city'><option selected="selected" value="{@ID}"><xsl:value-of select="."/></option></xsl:when>
				  <xsl:otherwise><option value="{@ID}"><xsl:value-of select="."/></option></xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
		</select>
		</xsl:if>

		<xsl:if test='@Type="1" and @ID="1"'>
		<select class="body" size="1" name="D{@ID}">
			<xsl:for-each select="Answer">
				<xsl:choose>
				  <xsl:when test='@ID=/Registration/Question/@place'><option selected="selected" value="{@ID}"><xsl:value-of select="."/></option></xsl:when>
				  <xsl:otherwise><option value="{@ID}"><xsl:value-of select="."/></option></xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
		</select>
		</xsl:if>

		<xsl:if test='@Type="1" and @ID="2"'>
		<select class="body" size="1" name="D{@ID}">
			<xsl:for-each select="Answer">
				<xsl:choose>
				  <xsl:when test='@ID=/Registration/Question/@place'><option selected="selected" value="{@ID}"><xsl:value-of select="."/></option></xsl:when>
				  <xsl:otherwise><option value="{@ID}"><xsl:value-of select="."/></option></xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
		</select>
		</xsl:if>

		<xsl:if test='@Type="2"'>
		<table>
		<xsl:variable name="radioID" select="concat('R',@ID)"></xsl:variable>

		<xsl:choose>
		<xsl:when test='@P1="1"'>
			<tr>
			<xsl:for-each select="Answer">
				<xsl:choose>
				  <xsl:when test='@Selected="1"'><td><input type="radio" checked="yes" value="{@ID}" name="{$radioID}"></input></td></xsl:when>
				  <xsl:when test='@Selected="0"'><td><input type="radio" value="{@ID}" name="{$radioID}"></input></td></xsl:when>
				</xsl:choose>
				<td class="body"><xsl:value-of select="."/></td>
			</xsl:for-each>
			</tr>
		</xsl:when>
		<xsl:when test='@P1="2"'>
			<xsl:for-each select="Answer">
				<tr>
					<xsl:choose>
					  <xsl:when test='@Selected="1"'><td><input type="radio" checked="yes" value="{@ID}" name="{$radioID}"></input></td></xsl:when>
					  <xsl:when test='@Selected="0"'><td><input type="radio" value="{@ID}" name="{$radioID}"></input></td></xsl:when>
					</xsl:choose>
				<td class="body"><xsl:value-of select="."/></td>
				</tr>
			</xsl:for-each>
		</xsl:when>
		</xsl:choose>

		</table>
		</xsl:if>

		<xsl:if test='@Type="3"'><nobr>
		<input type="text" id="{concat('gg',@ID)}" name="{concat('gg',@ID)}" class="form" size="2" maxlength="2" value="{@gg}"></input>
		/
		<input type="text" id="{concat('mm',@ID)}" name="{concat('mm',@ID)}" class="form" size="2" maxlength="2" value="{@mm}"></input>
		/
		<input type="text" id="{concat('aaaa',@ID)}" name="{concat('aaaa',@ID)}" class="form" size="4" maxlength="4" value="{@aaaa}"></input>
		<span class="body_10px_red"><xsl:value-of select="@Comment"/></span></nobr>
		</xsl:if>

		<xsl:if test='@Type="4"'>
			<input type="text" id="{concat('E',@ID)}" name="{concat('E',@ID)}" size="35" maxlength="64"></input>
			<br/><span class="body_10px_red"><xsl:value-of select="@Comment"/></span>
		</xsl:if>

		<xsl:if test='@Type="5"'>
			<xsl:choose>
			<xsl:when test='@ID="2"'>
				<input type="text" name="{concat('T',@ID)}" size="{@P2}" maxlength="{@P1}" value="{@title}"></input>
			</xsl:when>
			<xsl:otherwise>
				<input type="text" name="{concat('T',@ID)}" size="{@P2}" maxlength="{@P1}"></input>
			</xsl:otherwise>
			</xsl:choose>
			<br/><span class="body_10px_red"><xsl:value-of select="@Comment"/></span>
		</xsl:if>

		<xsl:if test='@Type="11"'>
			<input type="text" ID="T{@ID}" name="NICK{@ID}" size="{@P2}" maxlength="{@P1}"></input>
			<br/><span class="body_10px_red"><xsl:value-of select="@Comment"/></span>
		</xsl:if>

		<xsl:if test='@Type="12"'>
			<input type="password" ID="T{@ID}" name="PW{@ID}" size="{@P2}" maxlength="{@P1}"></input>
			<br/><span class="body_10px_red"><xsl:value-of select="@Comment"/></span>
		</xsl:if>

		<xsl:if test='@Type="13"'>
			<xsl:choose>
			<xsl:when test='@ID="3"'>
				<TEXTAREA id="TA{@ID}" name="TA{@ID}" rows="{@P1}" cols="{@P2}"><xsl:value-of select="@descr"/></TEXTAREA>
			</xsl:when>
			<xsl:otherwise>
				<TEXTAREA id="TA{@ID}" name="TA{@ID}" rows="{@P1}" cols="{@P2}"></TEXTAREA>
			</xsl:otherwise>
			</xsl:choose>
			<br/><span class="body_10px_red"><xsl:value-of select="@Comment"/></span>
		</xsl:if>

		<xsl:if test='@Type="6"'>
			<img src="{@Comment}" border="1"/>
		</xsl:if>

		</td>
		</tr>
	</xsl:otherwise>
</xsl:choose>

</xsl:for-each>


</form>
</table>
</xsl:template>

</xsl:stylesheet>